import AMapLoader from '@amap/amap-jsapi-loader';
window._AMapSecurityConfig = {
  securityJsCode: '237716e4a44b4c1b1e45e9280e7f189f'
}
// export const getAddressFn = (lnglat) => {
//   let locationStr;
//   AMapLoader.load({
//     key: "3ec0f4b64da67a9e6ade01ba12078cf8", // 设置您的key
//     version: "2.0",
//     plugins: ["AMap.Geocoder"],
//     AMapUI: {
//       version: "1.1",
//       plugins: []
//     },
//     Loca: {
//       version: "2.0"
//     }
//   })
//     .then((AMap) => {
//       let geocoder;
//       window.AMap.plugin('AMap.Geocoder', function () {
//         geocoder = new window.AMap.Geocoder({
//           // city 指定进行编码查询的城市，支持传入城市名、adcode 和 citycode
//           // city: '全国'
//         })
//       })
//       // 将经纬度转换成地址
//       geocoder.getAddress(lnglat, async (status, result) => {
//         console.log("result", result)
//         if (status === 'complete' && result.regeocode) {
//           locationStr = result.regeocode.formattedAddress;
//           console.log("0", locationStr)
//           return locationStr;
//         }
//       });
//     })
//   console.log("1", locationStr)
//   return locationStr;
// }
export function getAddressFn(lnglat){
  let locationStr;
  // let that = this;
  AMapLoader.load({
    key: "3ec0f4b64da67a9e6ade01ba12078cf8", // 设置您的key
    version: "2.0",
    plugins: ["AMap.Geocoder"],
    AMapUI: {
      version: "1.1",
      plugins: []
    },
    Loca: {
      version: "2.0"
    }
  })
    .then((AMap) => {
      let geocoder;
      window.AMap.plugin('AMap.Geocoder', function () {
        geocoder = new window.AMap.Geocoder({
          // city 指定进行编码查询的城市，支持传入城市名、adcode 和 citycode
          // city: '全国'
        })
      })
      // 将经纬度转换成地址
      geocoder.getAddress(lnglat, (status, result) => {
        console.log("result", result)
        if (status === 'complete' && result.regeocode) {
          locationStr = result.regeocode.formattedAddress;
          console.log("0", locationStr)
          return locationStr;
        }
      })
    })
    .catch(err => {
      console.log(err,'-------------err----------');
      return locationStr;
    })
}